Jul 95 Tips
Volume Number: 11
Issue Number: 7
Column Tag: Tips & Tidbits
Tips & Tidbits 
By Neil Ticktin, Editor-in-Chief with special thanks to Steve Sisak
Note: Source code files accompanying article are located on MacTech CD-ROM orsource code disks.
TIP OF THE MONTHTag Your PowerPC Code
With a Call To _eieio()
When disassembling PowerPC code with CodeWarrior, it isn’t always easy to find
the instructions associated with a given set of C statements. Putting in call like
Debugger(); can turn a leaf routine into a trunk.
If you use the CodeWarrior intrinsic __eieio(), this is no April Fools joke, it
will add the eieio instruction to the stream. Wrap your statements in this and moo.
Also, it is fairly benign to accidentally execute.
Chris Sears
sears@netcom.com
Load Extensions After Boot-Time.
This is a cool hack to load Extensions without restarting the Mac. It is the main part of
my Freeware utility LoadADrive 1.1, that can load a CD-ROM Driver after the Mac has
been started. (You can mount CDs without restarting your Mac if you haven’t switched
on your CD-ROM Drive at boot time. Works with System 7.x and even PowerMacs)
I also use this code to debug Extensions. It is anoying to reboot the mac all the
time. With this code as the main part of a small application and a good Debugger (I use
Jasik’s The Debugger) you can easily check the loading of the Extension.
I tested this code with some other Extensions and it works fine. Of course, this
simple version will definitly not work with most Extensions, but you can improve the
code to handle special situations.
Maybe someone, who has more free time than I have, will even develop an
Uninstaller for Extension. You have to keep track of all patches, allocated memory,
changes in Low Memory and so on. (not easy, I know :-)
I just want to demonstrate that it is NOT impossible to load Extensions after boot
time.
Dieter Spaar
Friedberg, Germany
Boolean LoadInit(FSSpecPtr extensionFSSpec)
{
short refNum, ret;
Handle hdl;
// Open resource fork
refNum = FSpOpenResFile(extensionFSSpec, fsCurPerm);
if(refNum == -1 || ResError() != noErr)
return FALSE; // Cannot open file
// Load INIT into System Zone
SetZone(SystemZone()); // Set zone to system zone
hdl = Get1IndResource(‘INIT’,1);
SetZone(ApplicZone());
CloseResFile(refNum);
return FALSE; // Cannot load INIT from driver
}
HLock(hdl); // lock the resource
HNoPurge(hdl);
// Call INIT, we don’t handle the return value ret here
ret = (*(short(*)())(*hdl))(); // Looks nice, doesn’t it ;-)
// Is it still a resource ? (don’t unlock if detached)
// Some INIT’s detach the resource to keep the INIT’s memory block
if(HGetState(hdl) & 0x20)
ReleaseResource(hdl);
}
SetZone(ApplicZone()); // Back to application zone
CloseResFile(refNum); // Close the resource file
// Redraw desktop (Extension may draw startup icon)
PaintOne(nil, GetGrayRgn());
return TRUE;
}
...And Thus Spake the App, “Another Bug!”
Have a piece of code that hard to debug with the debugger? Trying to debug a code
resource? Usually a quick and dirty solution is to put in a bunch of SysBeep(10) calls
to get an idea of where your code is at. However, you can use Apple’s Speech Manager
in a similar fashion and get a much better “speak-out”. Here’s how:
Include SpeakIt.c to your project. (The code is included on the disk, and at the
usual online places.) Include SpeakIt.h in all the files you want to have any debug
statements spoken. In SpeakIt.h is the macro DebugSpeech. Define it like “#define
DebugSpeech 1” when you want to use the speech debugger, and comment it out
when you don’t want to use it. Within the code you want to debug, call the speech
debugger by adding code like this example:
#ifdef DebugSpeech
CheckSpeechMgr(); // should be called once in your initialization code
#endif
. code ...
#ifdef DebugSpeech
SpeakIt( “Before while loop.”, true );
#endif
. more code ...
#ifdef DebugSpeech
SpeakIt( “Made it through the while loop.”, true );
#endif
. and more code ...
#ifdef DebugSpeech
SpeakIt( “Right before bringing up main window.”, true );
#endif
Cool!
Bill Modesitt
billm@maui.com, http://www.maui.com/~billm